#include "clogoper.h"
#include "cglobal.h"
#include "cpublicdata.h"

LogModule* CLogOper::getLogModule()
{
    if (m_pLogModule)
        return m_pLogModule;
    else
        return nullptr;
}

void CLogOper::setLogModule(LogModule *pModule)
{
    m_pLogModule = pModule;
}

void CLogOper::addLogTab(const QString &sGuid, int& nTabNo)
{
    if (m_pLogModule == nullptr) return;
    if (LogModule::enSuccess ==  m_pLogModule->appendTab(sGuid, nTabNo))
    {
        m_mapLogTab.insert(sGuid, nTabNo);
    }
}

QTableView *CLogOper::getLogTab(const QString &sGuid)
{
    if (m_pLogModule == nullptr) return nullptr;
    if (true == m_mapLogTab.contains(sGuid))
    {
        int nTabNo = m_mapLogTab.value(sGuid);
        return m_pLogModule->getTab(nTabNo);
    }
    else
        return nullptr;
}

void CLogOper::returnTab(QTableView* pTable)
{
    if (m_pLogModule == nullptr) return;
    m_pLogModule->returnTab(pTable);
}

void CLogOper::addMsg(QString sGuid, SExecLog sExecLog)
{
    if (m_pLogModule == nullptr) return;
    int nTabNo = m_mapLogTab.value(sGuid);
    if (nTabNo > 0)
    {
        if (m_mapLogTab.contains(sGuid))
        {
            int nTabNo = m_mapLogTab.value(sGuid);
            m_pLogModule->addMsg(sExecLog.m_nAlarmLevel, sExecLog.m_sDevName, sExecLog.m_sDescription, "", nTabNo);
        }
    }
    else
    {
        m_pLogModule->addMsg(sExecLog.m_nAlarmLevel, sExecLog.m_sDevName, sExecLog.m_sDescription);
    }

}

CLogOper::CLogOper()
    : m_pLogModule(nullptr)
{}

CLogOper::~CLogOper()
{
    //SAFE_DELETE(m_pLogModule)
}
